﻿/*
 * This file is part of MonoSettlers.
 *
 * Copyright (C) 2010-2011 Christoph Husse
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: 
 *      # Christoph Husse
 * 
 * Also checkout our homepage: http://opensettlers.codeplex.com/
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Globalization;
using MonoSettlers.RenderSystem;

namespace MonoSettlers
{
    public class DrawingBitmapConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var bitmap = value as System.Drawing.Bitmap;

            if (bitmap == null)
                return null;

            var stream = new System.IO.MemoryStream();

            bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);

            stream.Position = 0;

            return BitmapFrame.Create(stream);
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class AnimationPlayer : System.Windows.Forms.Integration.WindowsFormsHost
    {
        private GLRenderer m_Renderer;
        private AnimationClass m_Class;
        private RenderableAnimationClass m_Visual;

        public AnimationPlayer()
        {
            var container = new System.Windows.Forms.ContainerControl();

            container.Dock = System.Windows.Forms.DockStyle.Fill;

            m_Renderer = GLRenderer.CreateInControl(0, container);

            Child = container;
        }

        public Boolean Repeat { get; set; }

        public void Detach()
        {
            Child = null;
            m_Renderer.Dispose();
        }

        public AnimationClass Class
        {
            get { return m_Class; }
            set
            {
                if (m_Visual != null)
                    m_Renderer.RemoveVisual(m_Visual);

                m_Visual = m_Renderer.CreateAnimation(value, new PositionTracker(), value.Width);
                m_Class = value;
            }
        }

        public void Stop()
        {
        }

        public void Play(AnimationSet inSet)
        {
        }
    }
}
